package com.shuw.com.beingfortextproject.utils;

import java.util.Date;

import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

/**
 * Created by ${cs} on 2018/4/10.
 */

public class MailUtils {

	public static MimeMessage createMimeMessage(Session session, String sendMail, String receiveMail) throws Exception {
		// 1. 创建一封邮件
		MimeMessage message = new MimeMessage(session);
		// 2. From: 发件人
		message.setFrom(new InternetAddress(sendMail, "test", "UTF-8"));
		// 3. To: 收件人（可以增加多个收件人、抄送、密送）
		message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(receiveMail, "android客户端测试邮件", "UTF-8"));
		// 4. Subject: 邮件主题
		message.setSubject("邮件主题", "UTF-8");
		// 5. Content: 邮件正文（可以使用html标签）
		message.setContent("这是一条测试邮件", "text/html;charset=UTF-8");
		// 6. 设置发件时间
		message.setSentDate(new Date());
		// 7. 保存设置
		message.saveChanges();
		return message;
	}

}
